<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/commons/pages/taglibs.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>从机信息</title>
<link rel="stylesheet" type="text/css" href="../jquery-easyui/themes/${themes}/easyui.css">
<link rel="stylesheet" type="text/css" href="../jquery-easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../styles/demo.css">
<script type="text/javascript" src="../jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="../jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../jquery-easyui/plugins/jquery.datagrid-detailview.js"></script>
<script type="text/javascript" src="../jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../scripts/public.js.jsp"></script>
<script type="text/javascript" src="${ctx}/platform/type-info/format"></script>
</head>
<body>
<!--div class="demo-info">
  <div class="demo-tip icon-tip"></div>
  <div>从机信息</div>
</div-->
<c:if test="${true}">
  <div style="padding:5px; margin-bottom:5px; display:block;" class="combo">
    <form method="post" id="fm_search" novalidate style="display:inline-block">
      DTU ID：
        <select id="modem_id" name="modem_id" style="width:80px;">
      </select>
      从机ID:
      <select id="sid" name="sid">
        <option value="">请选择...</option>
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
        <option value="4">4</option>
        <option value="5">5</option>
        <option value="6">6</option>
        <option value="7">7</option>
        <option value="8">8</option>
        <option value="9">9</option>
        <option value="10">10</option>
        <option value="11">11</option>
        <option value="12">12</option>
        <option value="13">13</option>
        <option value="14">14</option>
        <option value="15">15</option>
        <option value="16">16</option>
        <option value="17">17</option>
        <option value="18">18</option>
        <option value="19">19</option>
        <option value="20">20</option>
        <option value="21">21</option>
        <option value="22">22</option>
        <option value="23">23</option>
        <option value="24">24</option>
        <option value="25">25</option>
      </select>
      <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="doSearch();">搜索</a> <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="$('#fm_search').form('clear');">重置</a>
    </form>
    <c:import url="__refresh.jsp" />
  </div>
</c:if>
<div id="dg"> </div>
<script type="text/javascript">
$(function(){
	//初始化列表
	$('#dg').datagrid({  
	    url:'${ctx}/platform/bmu-slave-info/search',
		queryParams:$('#fm_search').serializeObject(),
	    columns:[[
			{align:'center', /*width:160, */ title:'数据产生时间', field:'data_create_time', formatter:formatDateTimeNoYear},
            {align:'center', /*width:80 , */ title:'DTU ID', field:'modem_id'},
	        {align:'center', /*width:60 , */ title:'从机ID', field:'sid'},
	        {align:'right' , /*width:60 , */ title:'模块监控电池数目', field:'battery_count'},
	        {align:'right' , /*width:60 , */ title:'模块监控温感数目', field:'temp_sensor_count'},
	        {align:'right' , /*width:60 , */ title:'模块均衡电流数目', field:'balanced_series_count'},
	        {align:'right' , /*width:160, */ title:'热管理状态', field:'hot_manage_state', formatter:function (value) {
	        	value = new Number(value).toString(2).leftPad(8, "0");
	        	var status = [];
	        	status.push(["加热未开启", "加热开启"][parseInt(value.charAt(7))]);
	        	status.push(["风扇未开启", "风扇开启"][parseInt(value.charAt(6))]);
	        	return status.join(" | ");
	        }}
        ]],
		//fitColumns:true,
		striped:true,
		pagination:true,
		pageSize:20,
		remoteSort:false,
		rownumbers:true,
		singleSelect:true,
		autoSizeColumn:true,
		//子表
	    view: detailview,  
	    detailFormatter:function(index,row) {
	    	var divs = [];
	    	divs.push('<div style="padding:2px"><table id="state-' + index + '"></table></div>');
	    	divs.push('<div style="padding:2px"><table id="current-' + index + '"></table></div>');
	    	divs.push('<div style="padding:2px"><table id="boxtemp-' + index + '"></table></div>');
	    	return divs.join(''); 
	    },  
	    onExpandRow: function(index,row){  
	        $('#state-'+index).datagrid({  
	        	url:'${ctx}/platform/bmu-slave-info/search-state?bmu_slave_id=' + row.id,
	            //fitColumns:true,  
	            //singleSelect:true,  
	            //rownumbers:true,  
	            loadMsg:'',  
	            height:'auto',  
	            columns:[[  
					{align:'center', width:80,  title:'电池编号',     field:'battery_no'},
					{align:'right',  width:100, title:'电池电压(mV)', field:'battery_voltage'},
					{align:'center', width:120, title:'电池均衡状态', field:'balance_state', formatter:function (value) {
						return ["<span style='color:red;'>非均衡</span>", "<span style='color:green;'>均衡</span>"][parseInt(value)];
					}}
	            ]],  
	            onResize:function(){  
	                $('#dg').datagrid('fixDetailRowHeight',index);  
	            },  
	            onLoadSuccess:function(){  
	                setTimeout(function(){  
	                    $('#dg').datagrid('fixDetailRowHeight',index);  
	                },0);  
	            }
	        }); 
	        $('#current-'+index).datagrid({  
	        	url:'${ctx}/platform/bmu-slave-info/search-current?bmu_slave_id=' + row.id,
	            //fitColumns:true,  
	            //singleSelect:true,  
	            //rownumbers:true,  
	            loadMsg:'',  
	            height:'auto',  
	            columns:[[  
					{align:'center', width:80,  title:'串号', field:'serial_no'},
					{align:'right',  width:100, title:'均衡电流(mA)', field: 'serial_current'}
	            ]],  
	            onResize:function(){  
	                $('#dg').datagrid('fixDetailRowHeight',index);  
	            },  
	            onLoadSuccess:function(){  
	                setTimeout(function(){  
	                    $('#dg').datagrid('fixDetailRowHeight',index);  
	                },0);  
	            }
	        });  
	        $('#boxtemp-'+index).datagrid({  
	        	url:'${ctx}/platform/bmu-slave-info/search-boxtemp?bmu_slave_id=' + row.id,
	            //fitColumns:true,  
	            //singleSelect:true,  
	            //rownumbers:true,  
	            loadMsg:'',  
	            height:'auto',  
	            columns:[[  
					{align:'center', width:80,  title:'箱体号', field:'box_no'},
					{align:'right',  width:100, title:'箱体温度(℃)', field:'box_temp'}
	            ]],  
	            onResize:function(){  
	                $('#dg').datagrid('fixDetailRowHeight',index);  
	            },  
	            onLoadSuccess:function(){  
	                setTimeout(function(){  
	                    $('#dg').datagrid('fixDetailRowHeight',index);  
	                },0);  
	            }
	        });  
	        $('#dg').datagrid('fixDetailRowHeight',index);  
	    } 
	}); 
}); 
</script>
</body>
</html>